package com.example.controller;

import com.example.domain.Teacher;
import com.example.service.TeacherService;
import com.example.util.EasyuiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "/teacher")
@Slf4j
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public EasyuiResult<Teacher> list(@RequestParam(name = "page", defaultValue = "1", required = false) int page,
                                      @RequestParam(name = "rows", defaultValue = "10", required = false) int rows,
                                      @RequestParam(name = "sort", defaultValue = "id", required = false) String sort,
                                      @RequestParam(name = "order", defaultValue = "ASC", required = false) String order
    ) {
        
        log.info("教师列表,参数为 page={},row={},sort={},order={}", page, rows, sort, order);
        
        return teacherService.list(Teacher.USER_TEACHER, page - 1, rows, sort, order);
    }
    
    @RequestMapping(value = "/all", method = RequestMethod.POST)
    @ResponseBody
    public List<Teacher> all() {
        log.info("教师列表,不带参数");
        return teacherService.all();
    }
}
